package com.example.cinemasystemv2.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Table(name = "screenings")
public class Screening {
    @Id
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "movie_id", nullable = false)
    @JsonIgnore
    private Movie movie;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "room_id", nullable = false)
    @JsonIgnore
    private ScreeningRoom room;
    
    @Column(name = "startTime", nullable = false)
    private LocalDateTime startTime;
    
    @Column(name = "price", nullable = false)
    private double price;
    
    @OneToMany(mappedBy = "screening", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JsonIgnore
    private List<Order> orders;
    
    // 默认构造函数
    public Screening() {}
    
    // 带参构造函数
    public Screening(Movie movie, ScreeningRoom room, LocalDateTime startTime, double price) {
        this.movie = movie;
        this.room = room;
        this.startTime = startTime;
        this.price = price;
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Movie getMovie() {
        return movie;
    }
    
    public void setMovie(Movie movie) {
        this.movie = movie;
    }
    
    public ScreeningRoom getRoom() {
        return room;
    }
    
    public void setRoom(ScreeningRoom room) {
        this.room = room;
    }
    
    public LocalDateTime getStartTime() {
        return startTime;
    }
    
    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }
    
    public double getPrice() {
        return price;
    }
    
    public void setPrice(double price) {
        this.price = price;
    }
    
    public List<Order> getOrders() {
        return orders;
    }
    
    public void setOrders(List<Order> orders) {
        this.orders = orders;
    }
    
    // 业务方法
    public LocalDateTime getEndTime() {
        return startTime.plusMinutes(movie.getDuration());
    }
}